home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
BORL_TIP
/
TI100
/
TI555.ASC
< prev
next >
Wrap
Text File
|
1992-08-12
|
3KB
|
133 lines
PRODUCT : Turbo Pascal NUMBER : 555
VERSION : All
OS : Dos
DATE : August 12, 1992 PAGE : 1/2
TITLE : Network File Access
FILE AND RECORD LOCKING IN TURBO PASCAL
Turbo Pascal does not have built-in support for file and record
locking. It does, however, have the ability to open files for
shared access. This is accomplished by setting the value of the
system variable FileMode. By default, FileMode has a value of 2
which causes files opened to have single-user, read/write access.
A shared, read/write mode can be had by setting FileMode to a
value of 66. Whereas, a shared, read only mode is represented by
the value 64.
Record and file locking is a bit more difficult. DOS version 3.0
and later provide record locking through the use of Interrupt
21H, Service 5CH. This service may be accessed through Turbo
Pascal's procedure MsDos defined in the Dos unit.
Here's a routine designed to lock and unlock portions of any
untyped or type file. Note, these routines may not be used with
text files.
procedure LockBlock(var F; Offset: Longint; Length: LongInt;
Lock: Boolean);
type
LoHiRec = record
LoWord, HiWord: Word;
end;
var
RecordSize: Word;
Handle: Integer;
File: FileRec absolute F;
R: Registers;
begin
Handle := File.Handle;
RecordSize := File.RecSize;
Offset := Offset * RecordSize;
R.CX := LoHiRec(Offset).LoWord;
R.DX := LoHiRec(Offset).HiWord;
R.SI := LoHiRec(Length).LoWord;
R.DI := LoHiRec(Length).HiWord;
R.AH := $5C;
if Lock then R.AL := 0 else R.AL := 1;
MsDos(R);
if (R.Flags and FCarry) <> 0 then
PRODUCT : Turbo Pascal NUMBER : 555
VERSION : All
OS : Dos
DATE : August 12, 1992 PAGE : 2/2
TITLE : Network File Access
begin
RunError(R.AX);
end;
end;
The parameter 'offset' indicates what record is to mark the
beginning of the file lock. 'Length' determines how many records
will be locked from this point. The 'lock' parameter determines
whether the portion of the file is to be locked or unlocked.
To lock an entire file, pass 0 for offset and the results of the
FileSize function for the number of records to be locked.
This routine will function as expected when using SHARE and/or
MS-DOS compatible network software.
DISCLAIMER: You have the right to use this technical information
subject to the terms of the No-Nonsense License Statement that
you received with the Borland product to which this information
pertains.